using System;
using System.Collections;
using System.Collections.Generic;
using FrameWork;
using FrameWork.Inventory;
using UnityEngine;

/// <summary>
/// 玩家战斗以及环境检测
/// 血量
/// 拾取物品，检测环境
/// 其它需要全局调用的函数
/// </summary>
public class PlayerManager : SingletonMonoBehaviour<PlayerManager>, IAttack
{
    [SerializeField] private InventorySO myInventory;
    public InventorySO Inventory => myInventory;
    public bool IsCanAddItemToInventory => myInventory.GetInventoryState();

    public int AttackPhase { get; set; } = 1;
    private float timer = 5f;


    #region Life cycle function

    private void Start()
    {
        timer = 5f;
    }

    private void Update()
    {
        AttackPhaseUpdate();
    }

    #endregion

    #region Data update function

    private void AttackPhaseUpdate()
    {
        timer -= Time.deltaTime;
        if (timer <= 0)
        {
            AttackPhase = 1;
            timer = 5f;
        }
    }

    #endregion

    #region Attack function

    public void Attack(float damage)
    {
        // print("受到伤害");
        EventSystem.Instance.EventTrigger(EventName.EVENT_PLAYER_INFORMATION_UPDATE_HEALTH, -damage);
        
        Player.Instance.IsHit = true;
    }

    #endregion
}
